package com.audaque.springboot.foshanupload.web.reactivedemo.listener;

import com.audaque.springboot.foshanupload.web.reactivedemo.client.EchoClient;
import com.audaque.springboot.foshanupload.web.reactivedemo.reactor.MultiThreadEchoServerReactor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @author zgb
 * @desc ...
 * @date 2022-01-22 15:00:02
 */

@Component
@Slf4j
public class WebDemoApplicationReadyEventListener implements ApplicationListener<ApplicationEvent> {

    @Autowired
    private MultiThreadEchoServerReactor multiThreadEchoServerReactor;

    @Autowired
    private EchoClient echoClient;

    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {


        if (applicationEvent instanceof ApplicationReadyEvent) {
            log.debug("ApplicationReadyEvent:项目启动成功");
            multiThreadEchoServerReactor.startService();

            try {
                echoClient.start();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }

        }

    }
}
